<?php if (!defined('THINK_PATH')) exit(); /*a:2:{s:52:"themes/admin_simpleboot3/admin/department/index.html";i:1584585426;s:43:"themes/admin_simpleboot3/public/header.html";i:1584585426;}*/ ?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- HTML5 shim for IE8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <![endif]-->
    <title><?php echo Config('web_name'); ?></title>

    <link href="__TMPL__/public/assets/themes/<?php echo cmf_get_admin_style(); ?>/bootstrap.min.css" rel="stylesheet">
    <link href="__TMPL__/public/assets/simpleboot3/css/simplebootadmin.css" rel="stylesheet">
    <link href="__STATIC__/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <style>
        form .input-order {
            margin-bottom: 0px;
            padding: 0 2px;
            width: 42px;
            font-size: 12px;
        }

        form .input-order:focus {
            outline: none;
        }

        .table-actions {
            margin-top: 5px;
            margin-bottom: 5px;
            padding: 0px;
        }

        .table-list {
            margin-bottom: 0px;
        }

        .form-required {
            color: red;
        }
    </style>
    <script type="text/javascript">
        //全局变量
        var GV = {
            ROOT: "__ROOT__/",
            WEB_ROOT: "__WEB_ROOT__/",
            JS_ROOT: "static/js/",
            APP: '<?php echo \think\Request::instance()->module(); ?>'/*当前应用名*/
        };
    </script>
    <script src="__TMPL__/public/assets/js/jquery-1.10.2.min.js"></script>
    <script src="__STATIC__/js/wind.js"></script>
    <script src="__TMPL__/public/assets/js/bootstrap.min.js"></script>
    <script src="__TMPL__/public/assets/js/echarts.js"></script>
    <script>
        Wind.css('artDialog');
        Wind.css('layer');
        $(function () {
            $("[data-toggle='tooltip']").tooltip();
            $("li.dropdown").hover(function () {
                $(this).addClass("open");
            }, function () {
                $(this).removeClass("open");
            });
        });
    </script>
    <?php if(APP_DEBUG): ?>
        <style>
            #think_page_trace_open {
                z-index: 9999;
            }
        </style>
    <?php endif; ?>
<style>.expander{margin-left: -20px;}</style>
<style type="text/css">
	.icon{
		padding: 5px;
		cursor: pointer;
		display: none;
	}
	tbody tr:hover .icon{
		display: inline-block;
	}
	.tree_role{
		display: inline-block;
	}
	tbody tr p{
		color: #6892BF;
	} 
	tbody tr span.department_name{
		cursor: pointer;
	}
    .border_red{
        border:1px solid red;
    }
</style>
</head>
<body>
	<div class="wrap js-check-wrap">
		<div>
			<h3><?php echo $company['company_name']; ?> 部门管理</h3>
		</div>
		<ul class="nav nav-tabs">
			<li class="active"><a href="javascript:;">部门树状图</a></li>
		</ul>
			<div class="table_full">
				<table class="table table-bordered" id="department-tree">
					<tbody>
						<?php echo $category; ?>
					</tbody>
				</table>
			</div>
	</div>
	<!-- 模态框（Modal） -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						&times;
					</button>
					<h4 class="modal-title" id="myModalLabel">
						模态框（Modal）标题
					</h4>
				</div>
				<div class="modal-body">
					<form id="ajax-form" class="form-horizontal js-ajax-form margin-top-20" action="<?php echo url('department/addpost'); ?>" method="post">
						<input type="hidden" name="company_id" value="<?php echo $company['id']; ?>">
								<div class="form-group">
									<label for="input-name" class="col-sm-2 control-label"><span class="form-required">*</span>部门名称</label>
									<div class="col-md-6 col-sm-10">
										<input type="text" class="form-control" id="input-name" name="name">
									</div>
								</div>
								<div class="form-group">
									<label for="input-name" class="col-sm-2 control-label"><span class="form-required">*</span>上级部门</label>
									<div class="col-md-6 col-sm-10">
										<!-- <input type="text" class="form-control" id="input-name" name="parent_id"> -->
										<select name="parent_id" class="form-control">
											<?php echo $category2; ?>
										</select>
									</div>
								</div>
                                <div class="form-group">
                                    <label for="input-remark" class="col-sm-2 control-label"><span class="form-required">*</span>部门编号</label>
                                    <div class="col-md-6 col-sm-10">
                                        <input type="number" name="department_NO"  id="input-department_NO" class="form-control" required onchange="department_change(this);" readonly> 
                                    </div>
                                </div>
								<div class="form-group">
									<label for="input-remark" class="col-sm-2 control-label">部门备注</label>
									<div class="col-md-6 col-sm-10">
										<textarea style='resize: none;min-height: 150px;' type="text" class="form-control" id="input-remark" name="remark"></textarea>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label"><?php echo lang('STATUS'); ?></label>
									<div class="col-md-6 col-sm-10">
										<label class="radio-inline">
											<input type="radio" name="status" checked="checked" value="1"> <?php echo lang('ENABLED'); ?>
										</label>
										<label class="radio-inline">
											<input type="radio" name="status" value="0"> <?php echo lang('DISABLED'); ?>
										</label>
									</div>
								</div>
							</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭
					</button>
					<button id="ajax-post-add" type="button" class="btn btn-primary">
						添加部门
					</button>
					<button id="ajax-post-edit" type="button" class="btn btn-primary">
						提交更改
					</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal -->
	</div>
	<script src="__STATIC__/js/admin.js"></script>
    <script src="__STATIC__/js/layer/layer.js"></script>
	<script type="text/javascript">
		$(document).ready(function () {
		Wind.css('treeTable');
	    Wind.use('treeTable', function () {
	        $("#department-tree").treeTable({
	            indent: 20,
	            initialState: "expanded"
	        });
	    });
	    //ajax提交
	    $('#ajax-post-add').on('click',function() {
	    	var form = document.getElementById('ajax-form');
	    	var formData = new FormData(form);
	    	$.ajax({
	    		type : 'POST',
	    		url : "<?php echo url('department/ajaxAdd'); ?>", 
	    		data: formData,
	    		processData: false,  
	    		contentType: false,  
	    		success : function(data, textStatus, xhr) {
	    			$("#myModal").modal('hide');
	    			if (data.code == '1') {
	    				new Noty({
	    				    text: data.msg,
	    				    type: 'success',
	    				    layout: 'topCenter',
	    				    modal: true,
	    				    animation: {
	    				        open: 'animated bounceInDown', // Animate.css class names
	    				        close: 'animated bounceOutUp', // Animate.css class names
	    				    },
	    				    timeout: 1,
	    				    callbacks: {
	    				        afterClose: function () {
	    				            reloadPage(window);
	    				        }
	    				    }
	    				}).show();
	    			}else if (data.code == '0') {
                                art.dialog({
                                    content: data.msg,
                                    icon: 'warning',
                                    ok: function () {
                                        this.title(data.msg);
                                        return true;
                                    }
                                });
                            }
	    		}
	    	});
	    });

	    //获取父级ID
	    $(".department-tree").click(function() {
	    	var id = $(this).attr('id');
	    	$("form input[type = 'hidden']").remove();
	    	$(".modal-body select").val(id);
	    	$(".modal-body textarea").val("");
	    	$.get("<?php echo url('department/getDpNO'); ?>",function(data){
	    		$(".modal-body input[name='department_NO']").val(data);
	    	});
	    	
	    	//$(".modal-body input[type = 'radio']").removeProp('checked');
	    	$(".modal-body input[name = 'name']").val("");
	    	$('#ajax-post-edit').hide();
	    	$('#ajax-post-add').show();
	    	$("#myModalLabel").text('添加下级部门');
	    });

	    //ajax获取编辑内容
	    $('.ajax-edit').click(function() {
	    	$('#ajax-post-edit').show();
	    	$('#ajax-post-add').hide();
	    	$("#myModalLabel").text('修改部门信息');
	    	var id = $(this).attr('id');
	    	var inputId = "<input type='hidden' id = 'hiddenInput' name = 'id' value="+id+">";
	    	$(".modal-body form").append($(inputId));
	    	var url = $(this).attr('url');
	    	$.get(url,function (data,status) {

	    		$(".modal-body input[name = 'name']").val(data.name);
	    		$(".modal-body textarea").val(data.remark);
	    		$(".modal-body select").val(data.parent_id);
	    		$(".modal-body input[name='department_NO']").val(data.department_NO);
	    		$(".modal-body input[type = 'radio']").removeProp('checked');
	    		$(".modal-body input[value = "+ data.status +"]").prop('checked','checked');
	    	},'json');
	    });

	    //ajax提交编辑内容
	    $("#ajax-post-edit").on('click',function() {
	    	var form = document.getElementById('ajax-form');
	    	var formData = new FormData(form);
	    	$.ajax({
	    		type : 'POST',
	    		url : "<?php echo url('department/ajaxEditPost'); ?>", 
	    		data: formData,
	    		processData: false,  
	    		contentType: false,//不可指定编码
	    		//contentType: "application/x-www-form-urlencoded; charset=utf-8",   
	    		success : function(data, textStatus, xhr) {
	    			$("#myModal").modal('hide');
	    			if (data.code == '1') {
	    				new Noty({
	    				    text: data.msg,
	    				    type: 'success',
	    				    layout: 'topCenter',
	    				    modal: true,
	    				    animation: {
	    				        open: 'animated bounceInDown', // Animate.css class names
	    				        close: 'animated bounceOutUp', // Animate.css class names
	    				    },
	    				    timeout: 1,
	    				    callbacks: {
	    				        afterClose: function () {
	    				            reloadPage(window);
	    				        }
	    				    }
	    				}).show();
	    			}else if (data.code == '0') {
                                art.dialog({
                                    content: data.msg,
                                    icon: 'warning',
                                    ok: function () {
                                        this.title(data.msg);
                                        return true;
                                    }
                                });
                            }
	    		}
	    	});
	    });
	});

	jQuery(document).ready(function($) {
		$('#node-1').find('a.ajax-edit').hide();
		$('#node-1').find('a.js-ajax-delete').hide();
		$('#department-tree .badge').each(function(index, el) {
			var id = $(this).parent().find('a.department-tree').attr('id');
			var url = "<?php echo url('Department/getRole'); ?>";
			var elthis = $(this);
			url = url.replace('.html','/id/') + id;
			$.getJSON(url, function(data) {
				 if (data.count != 0) {
				 	if (data.user_count!=0) {
						elthis.html(data.user_count); 
				 	}
					for (var i = 0; i < data.name.length; i++) {
						var str = "<p>" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+"|"+"&nbsp;&nbsp;<span class='glyphicon glyphicon-user'></span>&nbsp;&nbsp;" +data.name[i] + "</p>";
						elthis.parent().find('.rolelist').append(str);
					}
				 }else{
				 	elthis.parent().find('.rolelist').remove();
				 }
			});
		});

		$('span.department_name').click(function(event) {
			id = $(this).parent().find('.department-tree').attr('id');
			var url = "<?php echo url('User/index'); ?>";
			url = url.replace('.html','/department_id/') + id;
			location.href = url;
		});
	});
	</script>
    <script>
        //检查部门编号
        function department_change(x){
            var url="<?php echo url('department/ajaxCheckNo'); ?>";
            var No=$(x).val();
            $.post(url,{no:No},function(data){
                if(data==1){
                    layer.alert('部门编号：'+No+' 已存在，请重新编号！');
                    $(x).val("");
                    $(x).focus();
                    $(x).addClass('border_red');
                }else{
                    $(x).removeClass('border_red');
                }
            },'json');
        }
    </script>
	<script src="__STATIC__/js/admin.js"></script>
</body>
</html>